package cn.wolfcode.car.base.service.impl;

import cn.wolfcode.car.base.domain.Customer;
import cn.wolfcode.car.base.domain.Post;
import cn.wolfcode.car.base.mapper.CustomerMapper;
import cn.wolfcode.car.base.query.CustomerQuery;
import cn.wolfcode.car.base.query.PostQuery;
import cn.wolfcode.car.base.service.ICustomerService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.util.Convert;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerServiceImpl implements ICustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public void deleteByPrimaryKey(Long id) {
        customerMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insert(Customer customer) {
        customerMapper.insert(customer);
    }

    @Override
    public Customer selectByPrimaryKey(Long id) {
        return customerMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Customer> selectAll() {
        return customerMapper.selectAll();
    }

    @Override
    public void updateByPrimaryKey(Customer customer) {
        customerMapper.updateByPrimaryKey(customer);
    }
    //分页过滤查询
    public TablePageInfo<Customer> query(CustomerQuery qo) {
        PageHelper.startPage(qo.getPageNum(), qo.getPageSize());
        return new TablePageInfo<Customer>(customerMapper.selectForList(qo));
    }

    //批量删除
    public void batchDelete(String ids) {
        //先使用工具类分割字符串为Long[]
        Long[] idArr = Convert.toLongArray(ids);
        for (Long id:idArr) {
            customerMapper.deleteByPrimaryKey(id);
        }
    }
}
